<template>
	<view class="container">
		<view class="searchBox">
			<input type="text" class="inputSearch" placeholder="请输入关键字" placeholder-class="placeholder" v-model="search"
				@input='input' />
			<image :src="baseurl+'project/search.png'" class="searchIcon"></image>
		</view>
		<view class="menuBox">
			<view class="menuItem" :class="menuIndex==index?'activeItem':''" v-for="(item,index) in menuArr"
				:key="index" @click="changeMenu(index)">
				{{item}}
			</view>
		</view>
		<scroll-view class="content" scroll-y="true" :scroll-into-view="clickId">
			<view class="projectItem" v-for="(item,index) in searchArr" :key="index" :id="'clickId' + index"
				@click="$navto.navto('../project_info/project_info',{id:item.id})">
				<image :src="item.cover" class="cover"></image>
				<image :src="baseurl+'project/mengban.png'" class="mengban"></image>
				<image :src="baseurl+'project/icon1.png'" v-if="item.sell_status==1" class="state"></image>
				<image :src="baseurl+'project/daishou.png'" v-else class="state"></image>
				<text class="name">{{item.name}}</text>
				<view class="priceBox">
					<text class="price">{{item.price}}</text>
					<!-- <text class="label">均价(元/m²)</text> -->
				</view>
				<view class="labelBox">
					<view class="labelItem" v-for="(item1,index1) in $strtoarr(item.tag,'/')" :key="index1">
						{{item1}}
					</view>
				</view>
				<view class="numBox">
					{{item.share_num}}人分享 | {{item.onlookers_num}}人围观
				</view>
			</view>
		</scroll-view>
		<view class="tabBarBox" v-if="isTab==1">
			<image src="@/static/tab/bg.png" class="tabbg"></image>
			<image src="@/static/tab/1s.png" class="projectTab" @click="$redirectTo('/packageB/project/project')">
			</image>
			<image src="@/static/tab/2.png" class="associationTab"
				@click="$redirectTo('/packageB/association/association')"></image>
			<image src="@/static/tab/3.png" class="homeTab" @click="$redirectTo('/pages/index/index')"></image>
			<image src="@/static/tab/4.png" class="mallTab" @click="$redirectTo('/packageB/category/category')"></image>
			<image src="@/static/tab/5.png" class="myTab" @click="$redirectTo('/pages/user/user')"></image>
		</view>
		<view class="tabBarBox" v-else>
			<image src="@/static/tab/bg.png" class="tabbg"></image>
			<image src="@/static/tab/1s.png" class="projectTab" @click="$redirectTo('/packageB/project/project')">
			</image>
			<!-- <image src="@/static/tab/2.png" class="associationTab"@click="$redirectTo('/packageB/association/association')"></image> -->
			<image src="@/static/tab/3.png" class="homeTab" @click="$redirectTo('/pages/index/index')"></image>
			<!-- <image src="@/static/tab/4.png" class="mallTab" @click="$redirectTo('/packageB/category/category')"></image> -->
			<image src="@/static/tab/5.png" class="myTab" @click="$redirectTo('/pages/user/user')"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseurl: this.$baseurl,
				content: '',
				page: 1,
				isTab: '',
				menuArr: [],
				menuIndex: -1,
				searchArr: [],
				search: '',
				clickId: '',
			}
		},
		onShow() {
			this.$request.get(`Community/submit_status`).then(res => {
				this.isTab = res.data.data;
			})
			uni.hideHomeButton()
			this.$request.get(`project/project_lists?page=${this.page}`).then(res => {
				console.log(res.data.data);
				this.content = res.data.data;
				this.searchArr = this.content;
				this.menuArr = this.content.map(item => item.name);
			})
		},
		onLoad() {
			
		},
		onReachBottom() {
			console.log("加载更多");
			this.page++;
			this.$request.get(`project/project_lists?page=${this.page}`).then(res => {
				console.log(res.data.data);
				this.content.push(...res.data.data);
			})
		},
		methods: {
			changeMenu(index){
				this.clickId = 'clickId'+index;
				this.menuIndex=index;
			},
			// 监听输入框变化
			input() {
				console.log('输入框变化了');
				this.searchArr = [];
				this.filterArr(this.content, this.search);
				//改变楼层数据
				// if (this.companySelArr.length > 0) {
				// 	this.isCompany = true;
				// } else {
				// 	this.isCompany = false;
				// }
				// if (this.company == '') {
				// 	this.isCompany = false;
				// }
			},
			filterArr(arrayOfObjects, searchString) {
				var filteredArray = arrayOfObjects.filter(function(obj) {
					return Object.values(obj).some(function(value) {
						return typeof value === 'string' && value.includes(searchString);
					});
				});
				console.log(filteredArray);
				if (filteredArray.length > 0) {
					this.searchArr = filteredArray;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.menuBox {
		position: fixed;
		width: 680rpx;
		margin-left: 35rpx;
		overflow-x: scroll;
		height: 60rpx;
		top: 200rpx;
		display: flex;
		flex-wrap: nowrap;

		.menuItem {
			font-size: 24rpx;
			height: 60rpx;
			line-height: 60rpx;
			padding-left: 20rpx;
			padding-right: 20rpx;
			border-radius: 10rpx;
			color: #4E97AD;
			background-color: #E1F6FC;
			margin-right: 50rpx;
			flex-shrink: 0;
		}

		.activeItem {
			background-color: #4E97AD;
			color: #fff;
		}
	}

	.searchBox {
		position: relative;
		width: 453rpx;
		height: 64rpx;
		margin-left: 40rpx;
		margin-top: 98rpx;
		background-color: #F0F0F0;
		border-radius: 32rpx;

		.searchIcon {
			position: absolute;
			width: 30rpx;
			height: 30rpx;
			left: 40rpx;
			top: 18rpx;
		}

		.inputSearch {
			width: 360rpx;
			height: 64rpx;
			border-radius: 32rpx;
			color: #000;
			font-size: 20rpx;
			font-weight: 500;
			padding-left: 90rpx;
		}
	}

	.projectItem {
		position: relative;
		width: 680rpx;
		height: 430rpx;
		margin-bottom: 30rpx;
		margin-left: 35rpx;
		border-radius: 15rpx;

		.mengban {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 680rpx;
			height: 214rpx;
		}

		.numBox {
			position: absolute;
			width: 245rpx;
			height: 26rpx;
			top: 367rpx;
			left: 435rpx;
			font-size: 16rpx;
			font-weight: 500;
			color: #fff;
		}

		.labelBox {
			position: absolute;
			width: 400rpx;
			height: 26rpx;
			top: 367rpx;
			left: 35rpx;
			display: flex;

			.labelItem {
				padding-left: 6rpx;
				padding-right: 6rpx;
				height: 26rpx;
				background-color: #4E97AD;
				border-radius: 4rpx;
				font-size: 14rpx;
				font-weight: 500;
				color: #fff;
				margin-right: 10rpx;
				line-height: 26rpx;
			}
		}

		.priceBox {
			position: absolute;
			right: 34rpx;
			top: 320rpx;
			display: flex;

			.label {
				font-size: 16rpx;
				font-weight: 500;
				color: #FFFFFF;
				margin-right: 0;
				margin-top: 17rpx;
			}

			.price {
				font-size: 32rpx;
				font-weight: 700;
				color: #FF6952;
				margin-right: 15rpx;
			}
		}

		.name {
			position: absolute;
			left: 34rpx;
			top: 320rpx;
			width: 400rpx;
			font-size: 26rpx;
			font-weight: 700;
			color: #fff;
		}

		.state {
			position: absolute;
			width: 56rpx;
			height: 62rpx;
			left: 34rpx;
		}

		.cover {
			position: absolute;
			width: 100%;
			height: 100%;
			border-radius: 15rpx;
		}
	}

	.container {
		position: fixed;
		width: 100%;
		height: 100vh;
		background-color: #fff;
		padding-bottom: 140rpx;
	}

	.content {
		position: fixed;
		width: 100%;
		top: 300rpx;
		max-height: 70vh;
		overflow-y: scroll;
		background-color: #fff;
	}
</style>